import { GameObject } from './GameObject'
import { Position, IPosition as IPosition } from './Position'
export class Food extends GameObject {
  el: HTMLElement
  protected _position: Position
  constructor() {
    super()
    this.el = document.getElementById('food')!
    this._position = new Position(this.el.offsetLeft, this.el.offsetTop)
  }
  get position() {
    return this._position
  }
  setPosition(val: IPosition) {
    this._position.positionX = val.positionX
    this._position.positionY = val.positionY
    this.el.style.left = val.positionX + 'px'
    this.el.style.top = val.positionY + 'px'
  }
  /**
   * 
   * @param minX 左边界最小值 
   * @param maxX 右边界最大值
   * @param minY 上边界
   * @param maxY 下边界
   */
  refreshRandom(minX: number, maxX: number, minY: number, maxY: number) {
    let x = Math.floor((Math.random() * (maxX - minX + 1)) / 10) * 10
    let y = Math.floor((Math.random() * (maxY - minY + 1)) / 10) * 10
    this.setPosition({positionX:x,positionY:y})
  }
}
